package com.sloera.nowcoder;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * class com.sloera.nowcoder
 * user sloera
 * date 2022/2/21
 */
public class HJ101 {
    // 注意类名必须为 Main, 不要有任何 package xxx 信息
    public static void main(String[] args) {
        order1();
        order2();
    }

    private static void order1() {
        Scanner in = new Scanner(System.in);
        int num = 0;
        if (in.hasNextInt()) {

            num = in.nextInt();
        }

        int[] array = new int[num];
        if (in.hasNextLine()) {
            for (int i = 0; i < num && in.hasNextInt(); i++) {
                array[i] = in.nextInt();
            }
        }
        int order = 0;
        if (in.hasNextInt()) {
            order = in.nextInt();
        }
        for (int i = 0; i < num - 1; i++) {
            for (int j = i; j < num; j++) {
                if (order == 0) {
                    if (array[i] > array[j]) {
                        int temp = array[i];
                        array[i] = array[j];
                        array[j] = temp;
                    }
                } else if (order == 1) {
                    if (array[i] < array[j]) {
                        int temp = array[i];
                        array[i] = array[j];
                        array[j] = temp;
                    }
                }
            }
        }
        for (int i = 0; i < num; i++) {
            System.out.print(array[i]);
            if (i < num - 1) {
                System.out.print(" ");
            }
        }
    }

    private static void order2() {
        Scanner in = new Scanner(System.in);
        int num = 0;
        if (in.hasNextInt()) {
            num = in.nextInt();
        }
        final ArrayList<Integer> integers = new ArrayList<>(num);
        if (in.hasNextLine()) {
            for (int i = 0; i < num && in.hasNextInt(); i++) {
                // array[i] = in.nextInt();
                integers.add(in.nextInt());
            }
        }
        int order = 0;
        if (in.hasNextInt()) {
            order = in.nextInt();
        }
        if (order == 0) {
            System.out.println(integers.stream().sorted().map(String::valueOf).collect(Collectors.joining(" ")));
        } else {
            System.out.println(integers.stream().sorted(Comparator.reverseOrder()).map(String::valueOf).collect(Collectors.joining(" ")));
        }
    }

    public static void exchange(int[] array, int start, int end) {
    }


}
